package Yatzee;
import java.awt.*;
import java.util.Random;


public class Wuerfel extends Canvas {
	private Random r;
	private int dimensionCanvas;
	private int dimensionAuge;
	private int augen;
	private boolean markiert;
	
	public Wuerfel() {
		super();
		this.setSize(70, 70);
		this.setBackground(Color.BLUE);
		this.markiert = false;
		
		dimensionCanvas= 70;
		dimensionAuge= 7;
		r = new Random();
	}
	
	public void paint(Graphics g) {
		
		g.setColor(Color.WHITE);
		
		switch (augen){
		case 1: g.fillOval(dimensionCanvas/2-dimensionAuge/2,
					dimensionCanvas/2-dimensionAuge/2, dimensionAuge, dimensionAuge);
		break;
		
		case 3:	g.fillOval(dimensionCanvas/2-dimensionAuge/2,
					dimensionCanvas/2-dimensionAuge/2, dimensionAuge, dimensionAuge);
				
				g.fillOval(dimensionAuge*2-dimensionAuge/2,dimensionAuge*2-dimensionAuge/2, 
						dimensionAuge, dimensionAuge);
				g.fillOval(dimensionCanvas-2*dimensionAuge-dimensionAuge/2, 
					dimensionCanvas-2*dimensionAuge-dimensionAuge/2, dimensionAuge, dimensionAuge);
		break;
				
		case 5: g.fillOval(dimensionCanvas/2-dimensionAuge/2,
					dimensionCanvas/2-dimensionAuge/2, dimensionAuge, dimensionAuge);
		
		case 4:	g.fillOval(dimensionAuge*2-dimensionAuge/2,dimensionCanvas-2*dimensionAuge-dimensionAuge/2, 
					dimensionAuge, dimensionAuge);
				g.fillOval(dimensionCanvas-2*dimensionAuge-dimensionAuge/2, 
					dimensionAuge*2-dimensionAuge/2, dimensionAuge, dimensionAuge);
					
		case 2: g.fillOval(dimensionAuge*2-dimensionAuge/2,dimensionAuge*2-dimensionAuge/2, 
					dimensionAuge, dimensionAuge);
				g.fillOval(dimensionCanvas-2*dimensionAuge-dimensionAuge/2, 
					dimensionCanvas-2*dimensionAuge-dimensionAuge/2, dimensionAuge, dimensionAuge);
		break;
		
		case 6:	g.fillOval(dimensionAuge*2-dimensionAuge/2,dimensionAuge*2-dimensionAuge/2, 
					dimensionAuge, dimensionAuge);
				g.fillOval(dimensionCanvas-2*dimensionAuge-dimensionAuge/2, 
						dimensionCanvas-2*dimensionAuge-dimensionAuge/2, dimensionAuge, dimensionAuge);

				g.fillOval(dimensionAuge*2-dimensionAuge/2,dimensionCanvas-2*dimensionAuge-dimensionAuge/2, 
						dimensionAuge, dimensionAuge);
				g.fillOval(dimensionCanvas-2*dimensionAuge-dimensionAuge/2, 
					dimensionAuge*2-dimensionAuge/2, dimensionAuge, dimensionAuge);
				
				g.fillOval(dimensionAuge*2-dimensionAuge/2, dimensionCanvas/2-dimensionAuge/2, 
						dimensionAuge, dimensionAuge);
				g.fillOval(dimensionCanvas-2*dimensionAuge-dimensionAuge/2, dimensionCanvas/2-dimensionAuge/2, 
						dimensionAuge, dimensionAuge);
		}
	}
	
	public int gibWert() {
		return augen;
	}
	
	public void markieren() {
		if(this.markiert) {
			this.markiert = false;
			this.setBackground(Color.blue);
		}
		else {
			this.markiert = true;
			this.setBackground(Color.gray);
		}
	}
	
	public boolean isMarkiert() {
		return markiert;
	}
	
	public void wuerfeln() {
		this.markiert = false;
		this.setBackground(Color.blue);
		this.augen = zufallszahl();
	}
	
	private int zufallszahl() {
		int zufall = r.nextInt(6) + 1;
		return zufall;
	}
}
